package com.xiaoze.databaseTableControl.controller;

import com.xiaoze.common.core.domain.AjaxResult;
import com.xiaoze.databaseTableControl.domain.DatabaseTable;
import com.xiaoze.databaseTableControl.domain.TableIndexAddInput;
import com.xiaoze.databaseTableControl.service.DataBaseTableService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

/**
 * @author 小泽
 * 接口描述: 对于数据库表的相关操作
 * @create 2024-12-11  16:09
 * 记得每天敲代码哦
 */
@RestController
@RequestMapping("/databaseTable")
public class DataBaseTableController {

    @Autowired
    private DataBaseTableService dataBaseTableService;

    /**
     * 方法描述: 获取所有的数据库列表
     *
     * @param :
     * @return com.xiaoze.common.core.domain.AjaxResult
     * @Author 胡昊泽
     * @Date 2024/12/11 16:17
     */
    @PreAuthorize("@ss.hasPermi('databaseTable:database:list')")
    @GetMapping("/getDatabaseList")
    public AjaxResult getDatabaseList(DatabaseTable database) {
        return AjaxResult.success(dataBaseTableService.getDatabaseList(database));
    }

    /**
     * 方法描述: 根据数据库名获取数据库表列表
     *
     * @param :
     * @return com.xiaoze.common.core.domain.AjaxResult
     * @Author 胡昊泽
     * @Date 2024/12/11 16:17
     */
    @PreAuthorize("@ss.hasPermi('databaseTable:table:list')")
    @GetMapping("/getDatabaseTableList")
    public AjaxResult getDatabaseTableList(DatabaseTable database) {
        return AjaxResult.success(dataBaseTableService.getDatabaseTableList(database));
    }

    /**
     * 方法描述: 根据数据库名和表名获取表的字段列表
     *
     * @param : databaseName 数据库名
     * @param : tableName 表名
     * @return com.xiaoze.common.core.domain.AjaxResult
     * @Date 2024/12/11 16:17
     */
    @PreAuthorize("@ss.hasPermi('databaseTable:column:list')")
    @GetMapping("/getDatabaseTableColumnList")
    public AjaxResult getDatabaseTableColumnList(DatabaseTable database) {
        return AjaxResult.success(dataBaseTableService.getDatabaseTableColumnList(database));
    }

    /**
     * 方法描述: 根据数据库名和表名获取表的sql语句
     *
     * @param database:
     * @return com.xiaoze.common.core.domain.AjaxResult
     * @Author 胡昊泽
     * @Date 2024/12/13 11:04
     */
    @PreAuthorize("@ss.hasPermi('databaseTable:createTable:query')")
    @GetMapping("/getDatabaseTableSql")
    public AjaxResult getDatabaseTableSql(DatabaseTable database) {
        return AjaxResult.success(dataBaseTableService.getDatabaseTableSql(database));
    }

    /**
    * 方法描述: 创建表索引
    * @Author 胡昊泽 
    * @Date 2024/12/16 10:09
      * @param tableIndexAddInput:
    * @return com.xiaoze.common.core.domain.AjaxResult
    */
    @PreAuthorize("@ss.hasPermi('databaseTable:createTableIndex:add')")
    @GetMapping("/createTableIndex")
    public AjaxResult createTableIndex(TableIndexAddInput tableIndexAddInput) {
        return AjaxResult.success(dataBaseTableService.createTableIndex(tableIndexAddInput));
    }
}
